<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script>
        /**
         * 对象解构
         * 1. 如果解构不成功，undefined
         * 2. 修改变量名
         * 3. 属性解析
         * */


        let {a,b} = {a:'1', b:'2'};// 1 2
        console.log(a,b);

        // TODO 如果解构不成功，undefined
        let {c} = {a:'1', b:'2'}
        console.log(c);// undefined

        // TODO null 不严格等于undefined
        let{d} = {};
        let{e} = {e:null};
        let{f} = {undefined};
        console.log(d,e,f);// undefined null undefined

        // TODO 修改变量名
        let {a:name} = {a:'aaa', b:'bbb'};
        console.log(name); // aaa
        /**
         * 原理
         * */
        // let {a:a, b:b} = {a:'aaa', b:'bbb'};
        // // 如果同名可省略
        // let {a, b} = {a:'aaa', b:'bbb'};

        // 属性解析
        let arr = [0, 1, 2, 3];
        console.log(arr);
        let {length} = arr;
        console.log(length); // 4
        // 取值
        let {0:a2, [arr.length-1]:b2} = arr;
        console.log(a2, b2);// 0 3
    </script>
</head>
<body>
    
</body>
</html>